package com.ruoyi.web.zangchat.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.text.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.zangchat.domain.ChatLogCash;
import com.ruoyi.web.zangchat.service.IChatLogCashService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 现金流水Controller
 * 
 * @author wudi
 * @date 2020-07-19
 */
@Controller
@RequestMapping("/zangchat/logcash")
public class ChatLogCashController extends BaseController
{
    private String prefix = "zangchat/logcash";

    @Autowired
    private IChatLogCashService chatLogCashService;

    @RequiresPermissions("zangchat:logcash:view")
    @GetMapping()
    public String logcash()
    {
        return prefix + "/logcash";
    }

    /**
     * 查询现金流水列表
     */
    @RequiresPermissions("zangchat:logcash:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String,Object> map)
    {
        startPage();
        return getDataTable(chatLogCashService.chatLogCashList(map));
    }

    /**
     * 导出现金流水列表
     */
    @RequiresPermissions("zangchat:logcash:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChatLogCash chatLogCash)
    {
        List<ChatLogCash> list = chatLogCashService.list(new QueryWrapper<>());
        ExcelUtil<ChatLogCash> util = new ExcelUtil<ChatLogCash>(ChatLogCash.class);
        return util.exportExcel(list, "logcash");
    }

    /**
     * 新增现金流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存现金流水
     */
    @RequiresPermissions("zangchat:logcash:add")
    @Log(title = "现金流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChatLogCash chatLogCash)
    {
        return toAjax(chatLogCashService.save(chatLogCash));
    }

    /**
     * 修改现金流水
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        ChatLogCash chatLogCash = chatLogCashService.getById(id);
        mmap.put("chatLogCash", chatLogCash);
        return prefix + "/edit";
    }

    /**
     * 修改保存现金流水
     */
    @RequiresPermissions("zangchat:logcash:edit")
    @Log(title = "现金流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChatLogCash chatLogCash)
    {
        return toAjax(chatLogCashService.updateById(chatLogCash));
    }

    /**
     * 删除现金流水
     */
    @RequiresPermissions("zangchat:logcash:remove")
    @Log(title = "现金流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatLogCashService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
    }
}
